//index.js


Page({
  data: {
    nickname: '', //名字

    avatarUrl: '',//头像

    data: '' //识别成功的卡号
  },

  onLoad: function () {

  },

  // 获取用户信息
  onGotUserInfo: function (e) {
    this.setData({
      nickname: e.detail.userInfo.nickName,
      avatarUrl: e.detail.userInfo.avatarUrl

    })

  },

  //点击进入我的卡片
  onMself: function (e) {
    wx.switchTab({
      url: '../home/home',
      success: function (res) {

      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  //点击进入添加页面
  onAdd: function (e) {
    wx.navigateTo({
      url: '../fill/fill',
    })
  },
  //点击进入自定义背景颜色
  onBackground: function (e) {
    wx.navigateTo({
      url: '../background/background',
    })
  },


  //点击进入银行卡识别


  onShow: function () {

    let that = this;
    wx.getUserInfo({
      withCredentials: true,
      lang: '',
      success: function (res) {

        that.setData({
          nickname: res.userInfo.nickName,
          avatarUrl: res.userInfo.avatarUrl
        })
      },
      fail: function (res) { },
      complete: function (res) { },
    })

    const db = wx.cloud.database()
    wx.cloud.callFunction({
      name: "login",

      success: res => {
        let openid = res.result.openid;

        db.collection('user').where({
          _openid: openid // 填入当前用户 openid
        }).get({
          success: function (res) {
            that.setData({
              image: res.data[0].image
            })
          }
        })
      },

      fail: res => {

      }
    })

  },


  onGetOpenid: function () {

  },


})